package com.qef.com.mmovie.mvp.interactor;

import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.api.DowLoadServer;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;

/**
 * Created by feq on 2017/7/21.
 */

public class DownloadInteractor {
    DowLoadServer dowLoadServer;

    @Inject
    public DownloadInteractor(DowLoadServer dowLoadServer) {
        this.dowLoadServer = dowLoadServer;
    }

    public Disposable getUpdata(String url, IGetDataDelegate<ResponseBody> iGetDataDelegate) {
        Logger.i(">>>>>>>>>>>>");
        return dowLoadServer.downloadFileWithDynamicUrlSync(url).
                compose(RxUtil.background()).subscribe(laughImgEntity ->
                iGetDataDelegate.getDataSuccess(laughImgEntity), throwable -> {
            throwable.printStackTrace();
            iGetDataDelegate.getDataError(throwable);
        });
    }

}
